package com.ysjweb.dish.config;

import com.ysjweb.dish.Service.impl.LoadMysqlImpl;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;

import java.util.List;

@Configuration
@EnableRetry
public class AiConfig {
    @Autowired
    private LoadMysqlImpl loadMysql;
    @Bean
    public EmbeddingStore store(){
        List<Document> documents=loadMysql.LoadMysql(200);
        //
        InMemoryEmbeddingStore store=new InMemoryEmbeddingStore();
        //
        EmbeddingStoreIngestor embeddingStore= EmbeddingStoreIngestor.builder()
                .embeddingStore(store)
                .build();
        embeddingStore.ingest(documents);
        return store;
    }
    @Bean
    public ContentRetriever contentRetriever(EmbeddingStore store){
        return EmbeddingStoreContentRetriever.builder()
                .embeddingStore(store)
                .minScore(0.5)
                .maxResults(6)
                .build();
    }
}
